global outfile "$results\Table 11A.xlsx"
global outfile2 "$results\Table 11B.xlsx"


* Inputs

scalar pre = 99.29
scalar effect = 0.1790
scalar deffect = 17.77
scalar price = 0.09
scalar pricecold = 0.03
scalar usd = 8.6
scalar instcost1 = 2000
scalar instcost2 = 1500
scalar maintain = 80
scalar i = 0.05
scalar kwhperl = 0.055
scalar life = 15


* Calculations

scalar freeride = 1/(1-effect)
scalar dbilleffect = deffect*price
scalar meffect = deffect*30
scalar yeffect = deffect*365
scalar deffectcold = deffect*3
scalar mbilleffect = meffect*price
scalar mbillpre = pre*30*price 
scalar ybilleffect = yeffect*price
scalar mbillpreusd = mbillpre/usd 
scalar mbilleffect = meffect*price
scalar mbilleffectusd = mbilleffect/usd 

scalar dwl = dbilleffect/2
scalar pvinst = instcost1+instcost2/((1+i)^life-1)
scalar ycostinst = pvinst*i 
scalar ycost = ycostinst+maintain
scalar dcost = ycost/365
scalar persekdwl = dwl/dcost
scalar persek = deffect/dcost
scalar persekcold = persek*3
scalar persekbilleffect = persek*price
scalar persekvaluehot = persek*pricecold
scalar persekvaluecold = persekcold*pricecold
scalar persekkwh = persek*kwhperl
scalar persekvaluekwh = persekbilleffect - persekvaluehot 

scalar persekwind = 1000/(24*usd) 
scalar perseksolarthermal = 1000/(132*usd) 
scalar persekchinalow = 1000/(250*usd) 
scalar persekchinahigh = 1000/(150*usd) 


* Section 2 - Institutionalia 

display mbillpre
display mbillpreusd


* Section 5 - Main estimates

display mbilleffect
display mbilleffectusd
display freeride


* Section 6 - CBA. Table 11A. Water and energy

local number = ycost
putexcel set "$outfile", sheet(example1) replace
putexcel A1 = "Variables"
putexcel B1 = "Standard case"
putexcel A2 = "Yearly cost"
putexcel B2 = `number'

local number = dcost
putexcel set "$outfile", sheet(example1) modify
putexcel A3 = "Daily cost"
putexcel B3 = `number'

local number = dbilleffect
putexcel set "$outfile", sheet(example1) modify
putexcel A4 = "Daily bill effect"
putexcel B4 = `number'

local number = dwl
putexcel set "$outfile", sheet(example1) modify
putexcel A5 = "DWL"
putexcel B5 = `number'

display persekdwl
local number = persekdwl
putexcel set "$outfile", sheet(example1) modify
putexcel A6 = "DWL/SEK IMB"
putexcel B6 = `number'

display persek
local number = persek
putexcel set "$outfile", sheet(example1) modify
putexcel A7 = "Hot water l/SEK IMB"
putexcel B7 = `number'

display persekvaluehot
local number = persekvaluehot
putexcel set "$outfile", sheet(example1) modify
putexcel A8 = "Hot water value/SEK IMB"
putexcel B8 = `number'

display persekbilleffect
local number = persekbilleffect
putexcel set "$outfile", sheet(example1) modify
putexcel A9 = "Bill effect/SEK IMB"
putexcel B9 = `number'

local number = persekcold
putexcel set "$outfile", sheet(example1) modify
putexcel A10 = "Total water l/SEK IMB)"
putexcel B10 = `number'

local number = persekvaluecold
putexcel set "$outfile", sheet(example1) modify
putexcel A11 = "Total water value/SEK IMB"
putexcel B11 = `number'

local number = persekkwh
putexcel set "$outfile", sheet(example1) modify
putexcel A12 = "Energy kWh/SEK IMB"
putexcel B12 = `number'

local number = persekvaluekwh
putexcel set "$outfile", sheet(example1) modify
putexcel A13 = "Energy value/SEK IMB"
putexcel B13 = `number'


* Section 6 - CBA. Table 11B. Energy and SSC

capture program drop CBA
program CBA
    args nr co2perkwh scostco2usd
	global co2persek`nr' = persekkwh*`co2perkwh'
    global scostpersek`nr' = ${co2persek`nr'} * usd*`scostco2usd'
end

CBA 1 0.045 0.051
CBA 2 0.045 0.12
CBA 3 0.045 0.19
CBA 4 0.045 0.34

CBA 5 0.298 0.051
CBA 6 0.298 0.12
CBA 7 0.298 0.19
CBA 8 0.298 0.34

CBA 9 0.367 0.051
CBA 10 0.367 0.12
CBA 11 0.367 0.19
CBA 12 0.367 0.34

CBA 13 0.436 0.051
CBA 14 0.436 0.12
CBA 15 0.436 0.19
CBA 16 0.436 0.34

clear all
set obs 16
gen number = _n
gen co2persek = .
gen scostpersek = .

forvalues i = 1(1)16 {
	display ${co2persek`i'} 
	display ${scostpersek`i'}
}

forvalues i = 1(1)16 {
	replace co2persek = ${co2persek`i'} if _n == `i'
	replace scostpersek = ${scostpersek`i'} if _n == `i'
}

export excel using "$outfile2", replace














